/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.table.alarm;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import twaver.swing.SingleFiledLayout;
import twaver.table.TTable;

public class TableControlPanel extends JPanel{
	
	public TableControlPanel(final TTable table){
		this.setLayout(new SingleFiledLayout(SingleFiledLayout.COLUMN, SingleFiledLayout.FULL));
		
		final JCheckBox sortable = new JCheckBox("Sortable", table.isSortable());
		this.add(sortable);
		sortable.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.setSortable(sortable.isSelected());
			}
		});
		final JCheckBox multiColumnSortable = new JCheckBox("Multi Column Sortable", table.isMultiColumnSortable());
		this.add(multiColumnSortable);
		multiColumnSortable.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.setMultiColumnSortable(multiColumnSortable.isSelected());
			}
		});
		final JCheckBox showHorizontalLines = new JCheckBox("Show Horizontal Lines", table.getShowHorizontalLines());
		this.add(showHorizontalLines);
		showHorizontalLines.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.setShowHorizontalLines(showHorizontalLines.isSelected());
			}
		});
		
		final JCheckBox showVerticalLines = new JCheckBox("Show Vertical Lines", table.getShowVerticalLines());
		this.add(showVerticalLines);
		showVerticalLines.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.setShowVerticalLines(showVerticalLines.isSelected());
			}
		});
		
		final JCheckBox rowResizable = new JCheckBox("Row Resizable", table.isRowResizable());
		this.add(rowResizable);
		rowResizable.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.setRowResizable(rowResizable.isSelected());
			}
		});
		
		final JCheckBox columnResizable = new JCheckBox("Column Resizable", table.isColumnResizable());
		this.add(columnResizable);
		columnResizable.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.setColumnResizable(columnResizable.isSelected());
			}
		});
		
		final JCheckBox headAutoResizable = new JCheckBox("Head Auto Resizable", table.isHeadAutoResizable());
		this.add(headAutoResizable);
		headAutoResizable.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.setHeadAutoResizable(headAutoResizable.isSelected());
			}
		});
		
		final JCheckBox columnAutoResizable = new JCheckBox("Column Auto Resizable", table.isColumnAutoResizable());
		this.add(columnAutoResizable);
		columnAutoResizable.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.setColumnAutoResizable(columnAutoResizable.isSelected());
			}
		});
		
		final JCheckBox columnHeaderDraggable = new JCheckBox("Column Header Draggable", table.getTableHeader().getReorderingAllowed());
		this.add(columnHeaderDraggable);
		columnHeaderDraggable.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.getTableHeader().setReorderingAllowed(columnHeaderDraggable.isSelected());
			}
		});
		
		final JCheckBox columnHeaderResizable = new JCheckBox("Column Header Resizable", table.getTableHeader().getResizingAllowed());
		this.add(columnHeaderResizable);
		columnHeaderResizable.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.getTableHeader().setResizingAllowed(columnHeaderResizable.isSelected());
			}
		});
		
		final JButton resizableAllColumns = new JButton("Pack All Columns");
		this.add(resizableAllColumns);
		resizableAllColumns.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				table.packAllColumns(true);
			}
		});
	}
	
}